<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="JavaScript," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="作用Js  就是可以用来控制   结构  和 样式 。 变量的作用域12345全局变量：    1. 在最外层声明的变量。    2. 在函数体内部，但是没有声明var 的变量也是全局变量局部变量：    1, 在函数体内部的 声明的变量 事件三要素事件源事件12345678910111213onclick		鼠标单击ondblclick	鼠标双击onkeyup		按下并释放键盘上的一个键时触发">
<meta name="keywords" content="JavaScript">
<meta property="og:type" content="article">
<meta property="og:title" content="前端JavaScript（一）">
<meta property="og:url" content="http://yoursite.com/2016/11/29/前端JavaScript（一）/index.html">
<meta property="og:site_name" content="JokerLiang">
<meta property="og:description" content="作用Js  就是可以用来控制   结构  和 样式 。 变量的作用域12345全局变量：    1. 在最外层声明的变量。    2. 在函数体内部，但是没有声明var 的变量也是全局变量局部变量：    1, 在函数体内部的 声明的变量 事件三要素事件源事件12345678910111213onclick		鼠标单击ondblclick	鼠标双击onkeyup		按下并释放键盘上的一个键时触发">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://ohe49035j.bkt.clouddn.com/html9.png">
<meta property="og:updated_time" content="2016-11-30T10:05:23.654Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="前端JavaScript（一）">
<meta name="twitter:description" content="作用Js  就是可以用来控制   结构  和 样式 。 变量的作用域12345全局变量：    1. 在最外层声明的变量。    2. 在函数体内部，但是没有声明var 的变量也是全局变量局部变量：    1, 在函数体内部的 声明的变量 事件三要素事件源事件12345678910111213onclick		鼠标单击ondblclick	鼠标双击onkeyup		按下并释放键盘上的一个键时触发">
<meta name="twitter:image" content="http://ohe49035j.bkt.clouddn.com/html9.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2016/11/29/前端JavaScript（一）/"/>





  <title> 前端JavaScript（一） | JokerLiang </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  








  <div style="display: none;">
    <script src="//s95.cnzz.com/z_stat.php?id=1260895995&web_id=1260895995" language="JavaScript"></script>
  </div>





  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">JokerLiang</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">永远年轻，永远热泪盈眶。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://yoursite.com/2016/11/29/前端JavaScript（一）/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="JokerLiang">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/me.jpg">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="JokerLiang">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="JokerLiang" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                前端JavaScript（一）
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2016-11-29T19:35:06+08:00">
                2016-11-29
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/前端基本功/" itemprop="url" rel="index">
                    <span itemprop="name">前端基本功</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="&#x4F5C;&#x7528;"><a href="#&#x4F5C;&#x7528;" class="headerlink" title="&#x4F5C;&#x7528;"></a>&#x4F5C;&#x7528;</h2><p>Js  &#x5C31;&#x662F;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x63A7;&#x5236;   &#x7ED3;&#x6784;  &#x548C; &#x6837;&#x5F0F; &#x3002;</p>
<h2 id="&#x53D8;&#x91CF;&#x7684;&#x4F5C;&#x7528;&#x57DF;"><a href="#&#x53D8;&#x91CF;&#x7684;&#x4F5C;&#x7528;&#x57DF;" class="headerlink" title="&#x53D8;&#x91CF;&#x7684;&#x4F5C;&#x7528;&#x57DF;"></a>&#x53D8;&#x91CF;&#x7684;&#x4F5C;&#x7528;&#x57DF;</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF1A;</span><br><span class="line">    1. &#x5728;&#x6700;&#x5916;&#x5C42;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#x3002;</span><br><span class="line">    2. &#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#xFF0C;&#x4F46;&#x662F;&#x6CA1;&#x6709;&#x58F0;&#x660E;var &#x7684;&#x53D8;&#x91CF;&#x4E5F;&#x662F;&#x5168;&#x5C40;&#x53D8;&#x91CF;</span><br><span class="line">&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#xFF1A;</span><br><span class="line">    1, &#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x7684; &#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;</span><br></pre></td></tr></table></figure>
<h2 id="&#x4E8B;&#x4EF6;&#x4E09;&#x8981;&#x7D20;"><a href="#&#x4E8B;&#x4EF6;&#x4E09;&#x8981;&#x7D20;" class="headerlink" title="&#x4E8B;&#x4EF6;&#x4E09;&#x8981;&#x7D20;"></a>&#x4E8B;&#x4EF6;&#x4E09;&#x8981;&#x7D20;</h2><h3 id="&#x4E8B;&#x4EF6;&#x6E90;"><a href="#&#x4E8B;&#x4EF6;&#x6E90;" class="headerlink" title="&#x4E8B;&#x4EF6;&#x6E90;"></a>&#x4E8B;&#x4EF6;&#x6E90;</h3><h3 id="&#x4E8B;&#x4EF6;"><a href="#&#x4E8B;&#x4EF6;" class="headerlink" title="&#x4E8B;&#x4EF6;"></a>&#x4E8B;&#x4EF6;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">onclick		&#x9F20;&#x6807;&#x5355;&#x51FB;</span><br><span class="line">ondblclick	&#x9F20;&#x6807;&#x53CC;&#x51FB;</span><br><span class="line">onkeyup		&#x6309;&#x4E0B;&#x5E76;&#x91CA;&#x653E;&#x952E;&#x76D8;&#x4E0A;&#x7684;&#x4E00;&#x4E2A;&#x952E;&#x65F6;&#x89E6;&#x53D1; </span><br><span class="line">onchange 	&#x6587;&#x672C;&#x5185;&#x5BB9;&#x6216;&#x4E0B;&#x62C9;&#x83DC;&#x5355;&#x4E2D;&#x7684;&#x9009;&#x9879;&#x53D1;&#x751F;&#x6539;&#x53D8;</span><br><span class="line">onfocus 	&#x83B7;&#x5F97;&#x7126;&#x70B9;&#xFF0C;&#x8868;&#x793A;&#x6587;&#x672C;&#x6846;&#x7B49;&#x83B7;&#x5F97;&#x9F20;&#x6807;&#x5149;&#x6807;&#x3002;</span><br><span class="line">onblur 		&#x5931;&#x53BB;&#x7126;&#x70B9;&#xFF0C;&#x8868;&#x793A;&#x6587;&#x672C;&#x6846;&#x7B49;&#x5931;&#x53BB;&#x9F20;&#x6807;&#x5149;&#x6807;&#x3002;</span><br><span class="line">onmouseover 	&#x9F20;&#x6807;&#x60AC;&#x505C;&#xFF0C;&#x5373;&#x9F20;&#x6807;&#x505C;&#x7559;&#x5728;&#x56FE;&#x7247;&#x7B49;&#x7684;&#x4E0A;&#x65B9;</span><br><span class="line">onmouseout 	&#x9F20;&#x6807;&#x79FB;&#x51FA;&#xFF0C;&#x5373;&#x79BB;&#x5F00;&#x56FE;&#x7247;&#x7B49;&#x6240;&#x5728;&#x7684;&#x533A;&#x57DF;</span><br><span class="line">onload		&#x7F51;&#x9875;&#x6587;&#x6863;&#x52A0;&#x8F7D;&#x4E8B;&#x4EF6;</span><br><span class="line">onunload	&#x5173;&#x95ED;&#x7F51;&#x9875;&#x65F6;</span><br><span class="line">onsubmit	&#x8868;&#x5355;&#x63D0;&#x4EA4;&#x4E8B;&#x4EF6;</span><br><span class="line">onreset		&#x91CD;&#x7F6E;&#x8868;&#x5355;&#x65F6;</span><br></pre></td></tr></table></figure>
<h3 id="&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"><a href="#&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;" class="headerlink" title="&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;"></a>&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;</h3><h2 id="&#x51FD;&#x6570;"><a href="#&#x51FD;&#x6570;" class="headerlink" title="&#x51FD;&#x6570;"></a>&#x51FD;&#x6570;</h2><p>&#x51FD;&#x6570;&#xFF1A; &#x51FD;&#x6570;&#x662F;&#x7531;&#x4E8B;&#x4EF6;&#x9A71;&#x52A8;&#x7684;&#x6216;&#x8005;&#x5F53;&#x5B83;&#x88AB;&#x8C03;&#x7528;&#x65F6;&#x6267;&#x884C;&#x7684;&#x53EF;&#x91CD;&#x590D;&#x4F7F;&#x7528;&#x7684;&#x4EE3;&#x7801;&#x5757;&#x3002;&#x7528;function&#x58F0;&#x660E;&#x3002;<br>&#x51FD;&#x6570;&#x9700;&#x8981;&#x8C03;&#x7528;&#x3002;<br><a id="more"></a><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">arguments&#x662F;&#x5B58;&#x50A8;&#x4E86;&#x51FD;&#x6570;&#x4F20;&#x9001;&#x8FC7;&#x8FC7;&#x6765;&#x5B9E;&#x53C2; </span><br><span class="line">Javascript&#x5728;&#x521B;&#x5EFA;&#x51FD;&#x6570;&#x7684;&#x540C;&#x65F6;&#xFF0C;&#x4F1A;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;arguments&#x5BF9;&#x8C61;&#x5B9E;&#x4F8B;.</span><br><span class="line">arguments&#x5BF9;&#x8C61;&#x53EA;&#x6709;&#x51FD;&#x6570;&#x5F00;&#x59CB;&#x65F6;&#x624D;&#x53EF;&#x7528;&#x3002;&#x51FD;&#x6570;&#x7684; arguments &#x5BF9;&#x8C61;&#x5E76;&#x4E0D;&#x662F;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x8BBF;&#x95EE;&#x5355;&#x4E2A;&#x53C2;&#x6570;&#x7684;&#x65B9;&#x5F0F;&#x4E0E;&#x8BBF;&#x95EE;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x7684;&#x65B9;&#x5F0F;&#x76F8;&#x540C;</span><br><span class="line">arguments&#x5BF9;&#x8C61;&#x7684;&#x957F;&#x5EA6;&#x662F;&#x7531;&#x5B9E;&#x53C2;&#x4E2A;&#x6570;&#x800C;&#x4E0D;&#x662F;&#x5F62;&#x53C2;&#x4E2A;&#x6570;&#x51B3;&#x5B9A;&#x7684;</span><br></pre></td></tr></table></figure></p>
<h2 id="&#x5224;&#x65AD;&#x7528;&#x6237;&#x8F93;&#x5165;&#x4E8B;&#x4EF6;"><a href="#&#x5224;&#x65AD;&#x7528;&#x6237;&#x8F93;&#x5165;&#x4E8B;&#x4EF6;" class="headerlink" title="&#x5224;&#x65AD;&#x7528;&#x6237;&#x8F93;&#x5165;&#x4E8B;&#x4EF6;"></a>&#x5224;&#x65AD;&#x7528;&#x6237;&#x8F93;&#x5165;&#x4E8B;&#x4EF6;</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&#x6B63;&#x5E38;&#x6D4F;&#x89C8;&#x5668;  :    oninput  </span><br><span class="line">Ie 678  &#x652F;&#x6301;&#x7684;  &#xFF1A; onpropertychange</span><br></pre></td></tr></table></figure>
<h2 id="&#x6392;&#x4ED6;&#x601D;&#x60F3;"><a href="#&#x6392;&#x4ED6;&#x601D;&#x60F3;" class="headerlink" title="&#x6392;&#x4ED6;&#x601D;&#x60F3;"></a>&#x6392;&#x4ED6;&#x601D;&#x60F3;</h2><p>&#x9996;&#x5148;&#x5E72;&#x6389;&#x6240;&#x6709;&#x4EBA;&#xFF0C;   &#x5269;&#x4E0B;&#x6211;&#x81EA;&#x5DF1;<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">  &lt;script&gt;</span><br><span class="line">    <span class="built_in">window</span>.onload = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>{</span><br><span class="line">        <span class="keyword">var</span> btns = <span class="built_in">document</span>.getElementsByTagName(<span class="string">&quot;button&quot;</span>);</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">var</span> i=<span class="number">0</span>;i&lt;btns.length;i++)</span><br><span class="line">        {</span><br><span class="line">            btns[i].onclick = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>{</span><br><span class="line">                <span class="comment">//&#x6E05;&#x9664;&#x6240;&#x6709;&#x4EBA;&#x7684; &#x7C7B;&#x540D;   &#x53EA;&#x80FD;&#x7528; for &#x904D;&#x5386;</span></span><br><span class="line">                <span class="keyword">for</span>(<span class="keyword">var</span> j=<span class="number">0</span>;j&lt;btns.length;j++)</span><br><span class="line">                {</span><br><span class="line">                    btns[j].className = <span class="string">&quot;&quot;</span>;</span><br><span class="line">                }</span><br><span class="line">                <span class="comment">//&#x5C31;&#x5269;&#x4E0B;&#x81EA;&#x5DF1; &#x5C31;&#x662F;&#x4E00;&#x4E2A; &#x800C;&#x4E14;&#x662F;&#x70B9;&#x51FB;&#x90A3;&#x4E2A;</span></span><br><span class="line">                <span class="keyword">this</span>.className = <span class="string">&quot;damao&quot;</span>;</span><br><span class="line">            }</span><br><span class="line">        }</span><br><span class="line">    }</span><br><span class="line">&lt;<span class="regexp">/script&gt;</span></span><br></pre></td></tr></table></figure></p>
<h2 id="&#x6570;&#x7EC4;&#x5E38;&#x7528;&#x65B9;&#x6CD5;"><a href="#&#x6570;&#x7EC4;&#x5E38;&#x7528;&#x65B9;&#x6CD5;" class="headerlink" title="&#x6570;&#x7EC4;&#x5E38;&#x7528;&#x65B9;&#x6CD5;"></a>&#x6570;&#x7EC4;&#x5E38;&#x7528;&#x65B9;&#x6CD5;</h2><h3 id="&#x6DFB;&#x52A0;"><a href="#&#x6DFB;&#x52A0;" class="headerlink" title="&#x6DFB;&#x52A0;"></a>&#x6DFB;&#x52A0;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">3</span>,<span class="number">5</span>]; </span><br><span class="line">&#x6211;&#x4EEC;&#x60F3;&#x8981; &#x628A; <span class="number">7</span>  &#x8FD9;&#x4E2A;&#x6570;&#x5B57; &#x653E;&#x5230;  &#x8FD9;&#x4E2A;&#x6570;&#x7EC4;&#x7684;&#x540E;&#x9762; </span><br><span class="line">&#x6211;&#x60F3;&#x8981; [<span class="number">1</span>,<span class="number">3</span>,<span class="number">5</span>,<span class="number">7</span>];</span><br><span class="line"><span class="number">1.</span> push()    &#x540E;&#x9762;&#x63A8;&#x8FDB;&#x53BB;</span><br><span class="line">push() &#x65B9;&#x6CD5;&#x53EF;&#x5411;&#x6570;&#x7EC4;&#x7684;&#x672B;&#x5C3E;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x65B0;&#x7684;&#x957F;&#x5EA6;&#x3002;</span><br><span class="line">push &#x63A8;&#x8FDB;&#x53BB;   &#x653E; </span><br><span class="line"><span class="keyword">var</span> arr =[<span class="number">1</span>,<span class="number">3</span>,<span class="number">5</span>]   &#x2192;  arr.push(<span class="number">7</span>)  &#x2192; &#x7ED3;&#x679C;&#x53D8;&#x6210; :  [<span class="number">1</span>,<span class="number">3</span>,<span class="number">5</span>,<span class="number">7</span>];</span><br><span class="line"><span class="number">2.</span> unshift()    &#x4ECE;&#x6570;&#x7EC4;&#x7684;&#x524D;&#x9762;&#x653E;&#x5165;</span><br><span class="line">unshift() &#x65B9;&#x6CD5;&#x53EF;&#x5411;&#x6570;&#x7EC4;&#x7684;&#x5F00;&#x5934;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x6216;&#x66F4;&#x591A;&#x5143;&#x7D20;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x65B0;&#x7684;&#x957F;&#x5EA6;</span><br><span class="line"> <span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">3</span>,<span class="number">5</span>]  &#x2192;  arr.unshift(<span class="number">0</span>) &#x2192;  &#x7ED3;&#x679C;&#x53D8;&#x6210; [<span class="number">0</span>,<span class="number">1</span>,<span class="number">3</span>,<span class="number">5</span>]</span><br></pre></td></tr></table></figure>
<h3 id="&#x5220;&#x9664;"><a href="#&#x5220;&#x9664;" class="headerlink" title="&#x5220;&#x9664;"></a>&#x5220;&#x9664;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>pop()   &#x5220;&#x9664;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</span><br><span class="line"><span class="keyword">var</span>  arr = [<span class="number">1</span>,<span class="number">3</span>,<span class="number">5</span>]   &#x2192;  arr.pop()  &#x2192;  &#x7ED3;&#x679C;   [<span class="number">1</span>,<span class="number">3</span>]  </span><br><span class="line"><span class="number">2.</span> shift()  &#x5220;&#x9664;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</span><br><span class="line">shift() &#x65B9;&#x6CD5;&#x7528;&#x4E8E;&#x628A;&#x6570;&#x7EC4;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x4ECE;&#x5176;&#x4E2D;&#x5220;&#x9664;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x7684;&#x503C;</span><br><span class="line"><span class="keyword">var</span>  arr = [<span class="number">1</span>,<span class="number">3</span>,<span class="number">5</span>]   &#x2192;  arr.shift()  &#x2192;  &#x7ED3;&#x679C;   [<span class="number">3</span>,<span class="number">5</span>]</span><br></pre></td></tr></table></figure>
<h3 id="&#x8FDE;&#x63A5;&#x4E24;&#x4E2A;&#x6570;&#x7EC4;"><a href="#&#x8FDE;&#x63A5;&#x4E24;&#x4E2A;&#x6570;&#x7EC4;" class="headerlink" title="&#x8FDE;&#x63A5;&#x4E24;&#x4E2A;&#x6570;&#x7EC4;"></a>&#x8FDE;&#x63A5;&#x4E24;&#x4E2A;&#x6570;&#x7EC4;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">concat()</span><br><span class="line">&#x8BE5;&#x65B9;&#x6CD5;&#x7528;&#x4E8E;&#x8FDE;&#x63A5;&#x4E24;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x6570;&#x7EC4;&#x3002;&#x5B83;&#x4E0D;&#x4F1A;&#x6539;&#x53D8;&#x73B0;&#x6709;&#x7684;&#x6570;&#x7EC4;&#xFF0C;&#x800C;&#x4EC5;&#x4EC5;&#x4F1A;&#x8FD4;&#x56DE;&#x88AB;&#x8FDE;&#x63A5;&#x6570;&#x7EC4;&#x7684;&#x4E00;&#x4E2A;&#x526F;&#x672C; </span><br><span class="line"><span class="keyword">var</span> aa = [<span class="number">1</span>,<span class="number">3</span>,<span class="number">5</span>];  <span class="keyword">var</span> bb = [&#x201C;a&#x201D;,&#x201D;b&#x201D;,&#x201D;c&#x201D;];</span><br><span class="line">aa.concat(bb);     &#x7ED3;&#x679C;&#xFF1A;  [<span class="number">1</span>,<span class="number">3</span>,<span class="number">5</span>,&#x201C;a&#x201D;,&#x201D;b&#x201D;,&#x201D;c&#x201D;];</span><br></pre></td></tr></table></figure>
<h3 id="&#x628A;&#x6570;&#x7EC4;&#x8F6C;&#x6362;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;"><a href="#&#x628A;&#x6570;&#x7EC4;&#x8F6C;&#x6362;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;" class="headerlink" title="&#x628A;&#x6570;&#x7EC4;&#x8F6C;&#x6362;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;"></a>&#x628A;&#x6570;&#x7EC4;&#x8F6C;&#x6362;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">join()  </span><br><span class="line">&#x4F5C;&#x7528;&#x662F;&#x5C06;&#x6570;&#x7EC4;&#x5404;&#x4E2A;&#x5143;&#x7D20;&#x662F;&#x901A;&#x8FC7;&#x6307;&#x5B9A;&#x7684;&#x5206;&#x9694;&#x7B26;&#x8FDB;&#x884C;&#x8FDE;&#x63A5;&#x6210;&#x4E3A;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x3002;</span><br><span class="line">&#x8BED;&#x6CD5;</span><br><span class="line">arrayObject.join(separator)</span><br><span class="line">&#x6570;&#x7EC4;&#x540D;.join(&#x7B26;&#x53F7;) </span><br><span class="line">&#x6570;&#x7EC4;&#x8F6C;&#x6362;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;</span><br><span class="line">&#x53C2;&#x6570; separator &#x53EF;&#x9009;&#x3002;&#x6307;&#x5B9A;&#x8981;&#x4F7F;&#x7528;&#x7684;&#x5206;&#x9694;&#x7B26;&#x3002;&#x5982;&#x679C;&#x7701;&#x7565;&#x8BE5;&#x53C2;&#x6570;&#xFF0C;&#x5219;&#x4F7F;&#x7528;&#x9017;&#x53F7;&#x4F5C;&#x4E3A;&#x5206;&#x9694;&#x7B26;&#x3002;</span><br><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>];</span><br><span class="line"><span class="built_in">console</span>.log(arr.join(&#x201C;-&#x201D;))    &#x7ED3;&#x679C;&#x5C31;&#x662F;&#xFF1A;  <span class="number">1</span><span class="number">-2</span><span class="number">-3</span>    &#x5B57;&#x7B26;&#x4E32;</span><br></pre></td></tr></table></figure>
<h3 id="&#x628A;&#x5B57;&#x7B26;&#x8F6C;&#x6362;&#x4E3A;&#x6570;&#x7EC4;"><a href="#&#x628A;&#x5B57;&#x7B26;&#x8F6C;&#x6362;&#x4E3A;&#x6570;&#x7EC4;" class="headerlink" title="&#x628A;&#x5B57;&#x7B26;&#x8F6C;&#x6362;&#x4E3A;&#x6570;&#x7EC4;"></a>&#x628A;&#x5B57;&#x7B26;&#x8F6C;&#x6362;&#x4E3A;&#x6570;&#x7EC4;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"> split  </span><br><span class="line"> split() &#x65B9;&#x6CD5;&#x7528;&#x4E8E;&#x628A;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x5206;&#x5272;&#x6210;&#x5B57;&#x7B26;&#x4E32;&#x6570;&#x7EC4;</span><br><span class="line">&#x8BED;&#x6CD5;</span><br><span class="line"> stringObject.split(separator,howmany)</span><br><span class="line">&#x53C2;&#x6570; separator &#x53EF;&#x9009;&#x3002;&#x6307;&#x5B9A;&#x8981;&#x4F7F;&#x7528;&#x7684;&#x5206;&#x9694;&#x7B26;&#x3002;&#x5982;&#x679C;&#x7701;&#x7565;&#x8BE5;&#x53C2;&#x6570;&#xFF0C;&#x5219;&#x4F7F;&#x7528;&#x9017;&#x53F7;&#x4F5C;&#x4E3A;&#x5206;&#x9694;&#x7B26;&#x3002;</span><br><span class="line">howmany &#x53EF;&#x9009;&#x3002;&#x8BE5;&#x53C2;&#x6570;&#x53EF;&#x6307;&#x5B9A;&#x8FD4;&#x56DE;&#x7684;&#x6570;&#x7EC4;&#x7684;&#x6700;&#x5927;&#x957F;&#x5EA6;</span><br></pre></td></tr></table></figure>
<h2 id="DOM"><a href="#DOM" class="headerlink" title="DOM"></a>DOM</h2><p>DOM &#x4E3A;&#x6587;&#x6863;&#x63D0;&#x4F9B;&#x4E86;&#x7ED3;&#x6784;&#x5316;&#x8868;&#x793A;&#xFF0C;&#x5E76;&#x5B9A;&#x4E49;&#x4E86;&#x5982;&#x4F55;&#x901A;&#x8FC7;&#x811A;&#x672C;&#x6765;&#x8BBF;&#x95EE;&#x6587;&#x6863;&#x7ED3;&#x6784;&#x3002;<br>&#x76EE;&#x7684;&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x4E3A;&#x4E86;&#x80FD;&#x8BA9;js&#x64CD;&#x4F5C;html&#x5143;&#x7D20;&#x800C;&#x5236;&#x5B9A;&#x7684;&#x4E00;&#x4E2A;&#x89C4;&#x8303;&#x3002;</p>
<h2 id="&#x5C01;&#x88C5;&#x81EA;&#x5DF1;class&#x7C7B;"><a href="#&#x5C01;&#x88C5;&#x81EA;&#x5DF1;class&#x7C7B;" class="headerlink" title="&#x5C01;&#x88C5;&#x81EA;&#x5DF1;class&#x7C7B;"></a>&#x5C01;&#x88C5;&#x81EA;&#x5DF1;class&#x7C7B;</h2><p>  &#x539F;&#x7406;&#xFF1A; &#xFF08;&#x6838;&#x5FC3;&#xFF09;<br>   &#x6211;&#x4EEC;&#x8981;&#x53D6;&#x51FA;&#x6240;&#x6709;&#x7684;&#x76D2;&#x5B50;&#xFF0C; &#x5229;&#x7528;&#x904D;&#x5386;&#x7684;&#x65B9;&#x6CD5; &#xFF0C; &#x901A;&#x8FC7;&#x6BCF;&#x4E00;&#x4E2A;&#x76D2;&#x5B50;&#x7684;className &#x6765;&#x5224;&#x65AD;&#x3002;  &#x5982;&#x679C;&#x76F8;&#x7B49;&#x5C31;&#x7559;&#x4E0B;&#x3002;<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line">    <span class="built_in">window</span>.onload = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>{</span><br><span class="line">       <span class="comment">//&#x5C01;&#x88C5;&#x81EA;&#x5DF1;class&#x7C7B;&#x540D;</span></span><br><span class="line">        <span class="function"><span class="keyword">function</span> <span class="title">getClass</span>(<span class="params">classname</span>)</span>{</span><br><span class="line">            <span class="comment">//&#x5982;&#x679C;&#x6D4F;&#x89C8;&#x5668;&#x652F;&#x6301;&#xFF0C;&#x5219;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;</span></span><br><span class="line">            <span class="keyword">if</span>(<span class="built_in">document</span>.getElementsByClassName)</span><br><span class="line">            {</span><br><span class="line">                <span class="keyword">return</span> <span class="built_in">document</span>.getElementsByClassName(classname);</span><br><span class="line">            }</span><br><span class="line">            <span class="comment">// &#x4E0D;&#x652F;&#x6301;&#x7684; &#x6D4F;&#x89C8;&#x5668;</span></span><br><span class="line">            <span class="keyword">var</span> arr = []; <span class="comment">// &#x7528;&#x4E8E;&#x5B58;&#x653E;&#x6EE1;&#x8DB3;&#x7684;&#x6570;&#x7EC4;</span></span><br><span class="line">            <span class="keyword">var</span> dom = <span class="built_in">document</span>.getElementsByTagName(<span class="string">&quot;*&quot;</span>);</span><br><span class="line">            <span class="comment">//alert(dom.length);</span></span><br><span class="line">            <span class="keyword">for</span>(<span class="keyword">var</span> i=<span class="number">0</span>;i&lt;dom.length;i++)</span><br><span class="line">            {</span><br><span class="line">                <span class="keyword">if</span>(dom[i].className == classname)</span><br><span class="line">                {</span><br><span class="line">                    arr.push(dom[i]);</span><br><span class="line">                }</span><br><span class="line">            }</span><br><span class="line">            <span class="keyword">return</span> arr;</span><br><span class="line">        }</span><br><span class="line">        <span class="built_in">console</span>.log(getClass(<span class="string">&quot;demo&quot;</span>).length);</span><br><span class="line">    }</span><br><span class="line">&lt;<span class="regexp">/script&gt;</span></span><br></pre></td></tr></table></figure></p>
<h2 id="&#x8BBF;&#x95EE;&#x5173;&#x7CFB;"><a href="#&#x8BBF;&#x95EE;&#x5173;&#x7CFB;" class="headerlink" title="&#x8BBF;&#x95EE;&#x5173;&#x7CFB;"></a>&#x8BBF;&#x95EE;&#x5173;&#x7CFB;</h2><p><img src="http://ohe49035j.bkt.clouddn.com/html9.png" alt=""></p>
<h3 id="&#x7236;&#x8282;&#x70B9;"><a href="#&#x7236;&#x8282;&#x70B9;" class="headerlink" title="&#x7236;&#x8282;&#x70B9;"></a>&#x7236;&#x8282;&#x70B9;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#x7236; &#xFF1A;  parentNode</span><br></pre></td></tr></table></figure>
<h3 id="&#x5144;&#x5F1F;&#x8282;&#x70B9;"><a href="#&#x5144;&#x5F1F;&#x8282;&#x70B9;" class="headerlink" title="&#x5144;&#x5F1F;&#x8282;&#x70B9;"></a>&#x5144;&#x5F1F;&#x8282;&#x70B9;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">nextSibling  &#x4E0B;&#x4E00;&#x4E2A;&#x5144;&#x5F1F;    &#x4EB2;&#x7684;       ie 678 &#x8BA4;&#x8BC6;</span><br><span class="line">nextElementSibling   &#x5176;&#x4ED6;&#x6D4F;&#x89C8;&#x5668;&#x8BA4;&#x8BC6;&#x7684;     </span><br><span class="line"> </span><br><span class="line">previousSibling   &#x540C;&#x7406;  &#x4E0A;&#x4E00;&#x4E2A;&#x5144;&#x5F1F;   </span><br><span class="line">previousElementSibling</span><br><span class="line"></span><br><span class="line">&#x5FC5;&#x987B;&#x5148;&#x5199; &#x6B63;&#x5E38;&#x6D4F;&#x89C8;&#x5668;  &#x540E;&#x5199;  ie678</span><br></pre></td></tr></table></figure>
<h3 id="&#x5B50;&#x8282;&#x70B9;"><a href="#&#x5B50;&#x8282;&#x70B9;" class="headerlink" title="&#x5B50;&#x8282;&#x70B9;"></a>&#x5B50;&#x8282;&#x70B9;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">firstChild    &#x7B2C;&#x4E00;&#x4E2A;&#x5B69;&#x5B50;  ie678</span><br><span class="line">firstElementChild  &#x7B2C;&#x4E00;&#x4E2A;&#x5B69;&#x5B50;   &#x6B63;&#x5E38;&#x6D4F;&#x89C8;&#x5668;</span><br></pre></td></tr></table></figure>
<h3 id="&#x5B69;&#x5B50;&#x8282;&#x70B9;"><a href="#&#x5B69;&#x5B50;&#x8282;&#x70B9;" class="headerlink" title="&#x5B69;&#x5B50;&#x8282;&#x70B9;"></a>&#x5B69;&#x5B50;&#x8282;&#x70B9;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">childNodes    &#x9009;&#x51FA;&#x5168;&#x90E8;&#x7684;&#x5B69;&#x5B50;</span><br><span class="line">childNodes&#xFF1A;&#x5B83;&#x662F;&#x6807;&#x51C6;&#x5C5E;&#x6027;&#xFF0C;&#x5B83;&#x8FD4;&#x56DE;&#x6307;&#x5B9A;&#x5143;&#x7D20;&#x7684;&#x5B50;&#x5143;&#x7D20;&#x96C6;&#x5408;&#xFF0C;&#x5305;&#x62EC;HTML&#x8282;&#x70B9;&#xFF0C;&#x6240;&#x6709;&#x5C5E;&#x6027;&#xFF0C;&#x6587;&#x672C;&#x8282;&#x70B9;</span><br><span class="line">children   &#x91CD;&#x8981;  &#x9009;&#x53D6;&#x6240;&#x6709;&#x7684;&#x5B69;&#x5B50; &#xFF08;&#x53EA;&#x6709;&#x5143;&#x7D20;&#x8282;&#x70B9;&#xFF09;</span><br></pre></td></tr></table></figure>
<h2 id="dom-&#x7684;&#x8282;&#x70B9;&#x64CD;&#x4F5C;"><a href="#dom-&#x7684;&#x8282;&#x70B9;&#x64CD;&#x4F5C;" class="headerlink" title="dom &#x7684;&#x8282;&#x70B9;&#x64CD;&#x4F5C;"></a>dom &#x7684;&#x8282;&#x70B9;&#x64CD;&#x4F5C;</h2><h3 id="&#x521B;&#x5EFA;&#x8282;&#x70B9;"><a href="#&#x521B;&#x5EFA;&#x8282;&#x70B9;" class="headerlink" title="&#x521B;&#x5EFA;&#x8282;&#x70B9;"></a>&#x521B;&#x5EFA;&#x8282;&#x70B9;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> div = <span class="built_in">document</span>.creatElement(&#x201C;li&#x201D;);</span><br><span class="line"></span><br><span class="line"> &#x4E0A;&#x9762;&#x7684;&#x610F;&#x601D;&#x5C31;&#x662F; &#x751F;&#x6210;&#x4E00;&#x4E2A;&#x65B0;&#x7684;  li &#x6807;&#x7B7E;</span><br></pre></td></tr></table></figure>
<h3 id="&#x63D2;&#x5165;&#x8282;&#x70B9;"><a href="#&#x63D2;&#x5165;&#x8282;&#x70B9;" class="headerlink" title="&#x63D2;&#x5165;&#x8282;&#x70B9;"></a>&#x63D2;&#x5165;&#x8282;&#x70B9;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>  appendChild();    &#x6DFB;&#x52A0;&#x5B69;&#x5B50;     append &#x6DFB;&#x52A0;&#x7684;&#x610F;&#x601D;</span><br><span class="line">   &#x610F;&#x601D;&#xFF1A;  &#x6DFB;&#x52A0;&#x5B69;&#x5B50;   &#x653E;&#x5230;&#x76D2;&#x5B50;&#x7684; &#x6700;&#x540E;&#x9762;&#x3002;</span><br><span class="line"><span class="number">2.</span> insertBefore(&#x63D2;&#x5165;&#x7684;&#x8282;&#x70B9;&#xFF0C;&#x53C2;&#x7167;&#x8282;&#x70B9;)   &#x5B50;&#x8282;&#x70B9;  &#x6DFB;&#x52A0;&#x5B69;&#x5B50;</span><br><span class="line">    &#x5199;&#x6EE1;&#x4E24;&#x4E2A;&#x53C2;&#x6570;  </span><br><span class="line">demo.insertBefore(test,childrens[<span class="number">0</span>]);</span><br><span class="line">   &#x653E;&#x5230;&#x4E86;&#x7B2C;&#x4E00;&#x4E2A;&#x5B69;&#x5B50;&#x7684;&#x524D;&#x9762;  </span><br><span class="line">  &#x5982;&#x679C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;  &#x4E3A; <span class="literal">null</span>  &#x5219; &#x9ED8;&#x8BA4;&#x8FD9;&#x65B0;&#x751F;&#x6210;&#x7684;&#x76D2;&#x5B50;&#x653E;&#x5230;&#x6700;&#x540E;&#x9762;&#x3002;</span><br><span class="line">  demo.insertBefore(test,<span class="literal">null</span>);</span><br></pre></td></tr></table></figure>
<h3 id="&#x79FB;&#x9664;&#x8282;&#x70B9;"><a href="#&#x79FB;&#x9664;&#x8282;&#x70B9;" class="headerlink" title="&#x79FB;&#x9664;&#x8282;&#x70B9;"></a>&#x79FB;&#x9664;&#x8282;&#x70B9;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">removeChild()    &#x5B69;&#x5B50;&#x8282;&#x70B9;       </span><br><span class="line"><span class="keyword">var</span> da = <span class="built_in">document</span>.getElementById(<span class="string">&quot;xiongda&quot;</span>);</span><br><span class="line">demo.removeChild(da);</span><br></pre></td></tr></table></figure>
<h3 id="&#x514B;&#x9686;&#x8282;&#x70B9;"><a href="#&#x514B;&#x9686;&#x8282;&#x70B9;" class="headerlink" title="&#x514B;&#x9686;&#x8282;&#x70B9;"></a>&#x514B;&#x9686;&#x8282;&#x70B9;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">cloneNode();</span><br><span class="line">&#x590D;&#x5236;&#x8282;&#x70B9; </span><br><span class="line">&#x62EC;&#x53F7;&#x91CC;&#x9762;&#x53EF;&#x4EE5;&#x8DDF;&#x53C2;&#x6570;  &#xFF0C; &#x5982;&#x679C; &#x91CC;&#x9762;&#x662F; <span class="literal">true</span>  &#x6DF1;&#x5C42;&#x590D;&#x5236;&#xFF0C; &#x9664;&#x4E86;&#x590D;&#x5236;&#x672C;&#x76D2;&#x5B50;&#xFF0C;&#x8FD8;&#x590D;&#x5236;&#x5B50;&#x8282;&#x70B9;  </span><br><span class="line">&#x5982;&#x679C;&#x4E3A; <span class="literal">false</span>  &#x6D45;&#x5C42;&#x590D;&#x5236;   &#x53EA;&#x590D;&#x5236;   &#x672C;&#x8282;&#x70B9;  &#x4E0D;&#x590D;&#x5236; &#x5B50;&#x8282;&#x70B9;&#x3002;</span><br></pre></td></tr></table></figure>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/JavaScript/" rel="tag"># JavaScript</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/11/29/前端HTML-CSS-（三）/" rel="next" title="前端HTML+CSS（三）">
                <i class="fa fa-chevron-left"></i> 前端HTML+CSS（三）
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/11/29/前端JavaScript（二）/" rel="prev" title="前端JavaScript（二）">
                前端JavaScript（二） <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/me.jpg"
               alt="JokerLiang" />
          <p class="site-author-name" itemprop="name">JokerLiang</p>
          <p class="site-description motion-element" itemprop="description">永远年轻，永远热泪盈眶。</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">61</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/LoverJoker" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.zhihu.com/people/lover-easy-7/activities" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/2292572142/profile?rightmod=1&wvr=6&mod=personinfo" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Friends
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.knight.ac.cn/" title="Knight" target="_blank">Knight</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://lzllzl.cn/" title="Zayvion" target="_blank">Zayvion</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://chen97.com/" title="Chens" target="_blank">Chens</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#作用"><span class="nav-number">1.</span> <span class="nav-text">作用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#变量的作用域"><span class="nav-number">2.</span> <span class="nav-text">变量的作用域</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#事件三要素"><span class="nav-number">3.</span> <span class="nav-text">事件三要素</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#事件源"><span class="nav-number">3.1.</span> <span class="nav-text">事件源</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#事件"><span class="nav-number">3.2.</span> <span class="nav-text">事件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#事件处理程序"><span class="nav-number">3.3.</span> <span class="nav-text">事件处理程序</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#函数"><span class="nav-number">4.</span> <span class="nav-text">函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#判断用户输入事件"><span class="nav-number">5.</span> <span class="nav-text">判断用户输入事件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#排他思想"><span class="nav-number">6.</span> <span class="nav-text">排他思想</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#数组常用方法"><span class="nav-number">7.</span> <span class="nav-text">数组常用方法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#添加"><span class="nav-number">7.1.</span> <span class="nav-text">添加</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#删除"><span class="nav-number">7.2.</span> <span class="nav-text">删除</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#连接两个数组"><span class="nav-number">7.3.</span> <span class="nav-text">连接两个数组</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#把数组转换为字符串"><span class="nav-number">7.4.</span> <span class="nav-text">把数组转换为字符串</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#把字符转换为数组"><span class="nav-number">7.5.</span> <span class="nav-text">把字符转换为数组</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#DOM"><span class="nav-number">8.</span> <span class="nav-text">DOM</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#封装自己class类"><span class="nav-number">9.</span> <span class="nav-text">封装自己class类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#访问关系"><span class="nav-number">10.</span> <span class="nav-text">访问关系</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#父节点"><span class="nav-number">10.1.</span> <span class="nav-text">父节点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#兄弟节点"><span class="nav-number">10.2.</span> <span class="nav-text">兄弟节点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#子节点"><span class="nav-number">10.3.</span> <span class="nav-text">子节点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#孩子节点"><span class="nav-number">10.4.</span> <span class="nav-text">孩子节点</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#dom-的节点操作"><span class="nav-number">11.</span> <span class="nav-text">dom 的节点操作</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#创建节点"><span class="nav-number">11.1.</span> <span class="nav-text">创建节点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#插入节点"><span class="nav-number">11.2.</span> <span class="nav-text">插入节点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#移除节点"><span class="nav-number">11.3.</span> <span class="nav-text">移除节点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#克隆节点"><span class="nav-number">11.4.</span> <span class="nav-text">克隆节点</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">JokerLiang</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	




  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
      search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();
    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';
      $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = $( "entry", xmlResponse ).map(function() {
            return {
              title: $( "title", this ).text(),
              content: $("content",this).text(),
              url: $( "url" , this).text()
            };
          }).get();
          var $input = document.getElementById(search_id);
          var $resultContent = document.getElementById(content_id);
          $input.addEventListener('input', function(){
            var matchcounts = 0;
            var str='<ul class=\"search-result-list\">';
            var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
            $resultContent.innerHTML = "";
            if (this.value.trim().length > 1) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var content_index = [];
                var data_title = data.title.trim().toLowerCase();
                var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                var data_url = decodeURIComponent(data.url);
                var index_title = -1;
                var index_content = -1;
                var first_occur = -1;
                // only match artiles with not empty titles and contents
                if(data_title != '') {
                  keywords.forEach(function(keyword, i) {
                    index_title = data_title.indexOf(keyword);
                    index_content = data_content.indexOf(keyword);
                    if( index_title >= 0 || index_content >= 0 ){
                      isMatch = true;
                      if (i == 0) {
                        first_occur = index_content;
                      }
                    }

                  });
                }
                // show search results
                if (isMatch) {
                  matchcounts += 1;
                  str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                  var content = data.content.trim().replace(/<[^>]+>/g,"");
                  if (first_occur >= 0) {
                    // cut out 100 characters
                    var start = first_occur - 20;
                    var end = first_occur + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if(start == 0){
                      end = 50;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    var match_content = content.substring(start, end);
                    // highlight all keywords
                    keywords.forEach(function(keyword){
                      var regS = new RegExp(keyword, "gi");
                      match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                    });

                    str += "<p class=\"search-result\">" + match_content +"...</p>"
                  }
                  str += "</li>";
                }
              })};
            str += "</ul>";
            if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
            if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
            $resultContent.innerHTML = str;
          });
          proceedsearch();
        }
      });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  

  

  

  


</body>
</html>
